import 'package:flutter/material.dart';

class MyTheme {
  /// 主要颜色
  static const Color primaryColor = Color(0xFF466FFF);

  /// 次要颜色
  static const Color infoColor = Color(0xFF4E4B66);

  /// 错误颜色
  static const Color errorColor = Color(0xFFFF4141);

  /// 主要材料颜色
  static MaterialColor primaryMaterialColor = createMaterialColor(primaryColor);

  /// 次要材料颜色
  static MaterialColor infoMaterialColor = createMaterialColor(infoColor);

  /// 错误材料颜色
  static MaterialColor errorMaterialColor = createMaterialColor(errorColor);

  static ThemeData themeData = ThemeData(
    useMaterial3: true,
    scaffoldBackgroundColor: const Color(0xFFFFFFFF),
    colorScheme: ColorScheme.fromSwatch(
      primarySwatch: primaryMaterialColor,
      accentColor: primaryMaterialColor,
      errorColor: errorMaterialColor,
    ),
    textTheme: const TextTheme(
      displayLarge: TextStyle(
        fontSize: 32,
      ),
      displayMedium: TextStyle(
        fontSize: 24,
      ),
      displaySmall: TextStyle(
        fontSize: 22,
      ),
    ),
  );

  /// 创建材料颜色
  static MaterialColor createMaterialColor(Color color) {
    List strengths = <double>[.05];
    Map<int, Color> swatch = {};
    final int r = color.red, g = color.green, b = color.blue;

    for (int i = 1; i < 10; i++) {
      strengths.add(0.1 * i);
    }
    for (var strength in strengths) {
      final double ds = 0.5 - strength;
      swatch[(strength * 1000).round()] = Color.fromRGBO(
        r + ((ds < 0 ? r : (255 - r)) * ds).round(),
        g + ((ds < 0 ? g : (255 - g)) * ds).round(),
        b + ((ds < 0 ? b : (255 - b)) * ds).round(),
        1,
      );
    }
    return MaterialColor(color.value, swatch);
  }
}
